package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

class NUPfPr {
    // 2022-09-06 09:43:21
    public static void main(String[] args) {
        Solution solution = new NUPfPr().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public boolean canPartition(int[] nums) {
            int sum = 0;
            for (int num : nums) {
                sum += num;
            }
            if (sum % 2 != 0) {
                return false;
            }

            int halfSum = sum / 2;
            int[] dp = new int[halfSum + 1];

            for (int num : nums) {
                for (int j = halfSum; j >= num; j--) {
                    dp[j] = Math.max(dp[j], dp[j - num] + num);
                }
            }

            return dp[halfSum] == halfSum;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}